/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package edu.upn.sigemfi.vfi.bc;

import edu.upn.sigemfi.ope.be.Moneda;
import edu.upn.sigemfi.vfi.be.Caja;
import edu.upn.sigemfi.vfi.be.SaldoCaja;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import org.omg.CORBA.PUBLIC_MEMBER;

/**
 *
 * @author Alex
 */
@Stateless
public class SaldoCajaFacade implements SaldoCajaFacadeLocal {
   @PersistenceContext(unitName="edu.upn.sigemfi.vfi-ejbPU")
    private EntityManager em;

    public void create(SaldoCaja saldoCaja) {
        em.persist(saldoCaja);
    }

    public void edit(SaldoCaja saldoCaja) {
        em.merge(saldoCaja);
    }

    public void remove(SaldoCaja saldoCaja) {
        em.remove(em.merge(saldoCaja));
    }

    public SaldoCaja find(Object id) {
        return em.find(SaldoCaja.class, id);
    }

    public List<SaldoCaja> findAll() {
        return em.createQuery("select object(o) from SaldoCaja as o").getResultList();
    }


    public List<SaldoCaja> findByMontoAndCaja() {
     //   return em.createQuery("SELECT s FROM SaldoCaja s WHERE s.monto = :monto and s.fidVfiCaja = :fidVfiCaja")
        return em.createQuery("select object(o) from SaldoCaja as o").getResultList();
    }

    public SaldoCaja findbyMoneda(Object id, Object m) {

        return em.find(SaldoCaja.class, id);
    }

     public SaldoCaja buscarPorCajayMoneda(Caja fidVfiCaja, Moneda fidOpeMoneda) {
        


        return (SaldoCaja) em.createQuery("SELECT object(o) FROM SaldoCaja as o WHERE o.fidVfiCaja = :fidVfiCaja and o.fidOpeMoneda = :fidOpeMoneda").setParameter("fidVfiCaja", fidVfiCaja).setParameter("fidOpeMoneda", fidOpeMoneda) .getSingleResult();
    }
}
